package com.example.flowable.local;

import com.example.FlowableLocalDb;
import org.flowable.engine.HistoryService;
import org.flowable.engine.history.HistoricActivityInstance;

import java.util.List;

/**
 * 流程历史记录
 *
 * @author wsl
 */
public class HisFlowable extends FlowableLocalDb {

    /**
     * 查询给定流程定义的历史活动实例
     */
    public void queryHistoryActivity(){
        String processDefinitionId = "Leave:1";
        HistoryService historyService = processEngine.getHistoryService();
        List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery()
                .processDefinitionId(processDefinitionId)//给定流程定义的
                .finished()//已完成的
                .orderByHistoricActivityInstanceEndTime().desc()//按完成时间倒序排列的
                .list();
        for (HistoricActivityInstance historicActivityInstance : list) {
            System.out.println(
                    historicActivityInstance.getActivityName() + ":" + historicActivityInstance.getAssignee() + "--"
                    +historicActivityInstance.getActivityId() + ":" + historicActivityInstance.getDurationInMillis()
            );
        }
    }
}
